import java.util.Stack;

class MinStack {

    //声明
    Stack<Integer> stack;//普通栈
    Stack<Integer> minStack;//最小栈
    public MinStack() {
        //实例化
        stack=new Stack<>();
        minStack=new Stack<>();
    }
    
    public void push(int val) {
        //普通栈都得放,最小栈的话只有第一次会放
        stack.push(val);
        if(minStack.empty()) minStack.push(val);
        else {
            Integer tmp=minStack.peek();
            if(val<=tmp) {
                minStack.push(val);
            }
        }
    }
    
    public void pop() {
        //普通栈都得pop,最小栈的话只有两者栈顶元素相同才pop
        int tmp=stack.pop();//注意若这里吧tmp定义为Integer的话,下面minStack.peek和tmp进行比较要用equals,而定义为int时会发生自动拆箱可以用==
        if(minStack.empty()) return;//最小栈为空,直接返回
        if(minStack.peek()==tmp) {
            minStack.pop();
        }
    }
    
    public int top() {
        if(stack.empty()) return -1;
        return stack.peek();
    }
    
    public int getMin() {
        if(minStack.empty()) return -1;
        return minStack.peek();
    }
}

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack obj = new MinStack();
 * obj.push(val);
 * obj.pop();
 * int param_3 = obj.top();
 * int param_4 = obj.getMin();
 */